package com.zjs.dao.impl;

import com.zjs.bean.Users;
import com.zjs.dao.UsersDao;
import com.zjs.utils.DBUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UsersDaoImpl extends DBUtils implements UsersDao {
    /**
     * 通过用户名和密码获取用户信息
     *
     * @param loginName
     * @param password
     * @return
     */
    public Users getUser(String loginName, String password) {
        String sql = "select * from users where loginName=? and password=?";
        List param = new ArrayList<>();
        param.add(loginName);
        param.add(password);
        ResultSet query = query(sql, param);
        Users users = null;
        try {
            while (query.next()) {
                users = new Users();
                users.setUserId(query.getInt("userId"));
                users.setLoginName(query.getString("loginName"));
                users.setRealName(query.getString("realName"));
                users.setPassword(query.getString("password"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeAll();
        }
        return users;
    }
}
